<template>
  <el-menu
    class="el-menu-demo"
    mode="horizontal"
    background-color="#334157"
    text-color="#fff"
    active-text-color="#fff"
  >
    <el-submenu index="2" class="submenu">
      <template slot="title">{{ user.realName }}</template>
      <template slot="title">--超级管理员</template>
      <el-menu-item index="2-1">设置</el-menu-item>
      <el-menu-item @click="content()" index="2-2">个人中心</el-menu-item>
      <el-menu-item @click="logout()" index="2-3">退出</el-menu-item>
    </el-submenu>
  </el-menu>
</template>
  <script>
export default {
  name: "navcon",
  data() {
    return {
      user: {},
    };
  },
  // 创建完毕状态(里面是操作)
  created() {
    this.user = JSON.parse(sessionStorage.getItem("userdata"));
  },
  methods: {
    content(){},
    // 退出登录
    logout() {
      this.$confirm("退出登录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          //请求路径默认为/logout
          this.$axios.delete("logout").then((res) => {
            if (res.data.code == 200) {
              //清空localStorage对应的信息
              sessionStorage.setItem("authorization", "");
              this.$message.success(res.data.message);
              //跳转到登录页面
              this.$router.push("/");
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
  },
};
</script>
  <style scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  border: none;
}
.submenu {
  float: right;
}
.buttonimg {
  height: 60px;
  background-color: transparent;
  border: none;
}
.showimg {
  width: 26px;
  height: 26px;
  position: absolute;
  top: 17px;
  left: 17px;
}
.showimg:active {
  border: none;
}
</style>